using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ProtectiveItem : InventoryItem{
	public int maxDex = -1;
	public int checkPenalty;
	public int spellFailure;
	
	public ProtectiveItem()
	{
		slot = "Armor";
	}
	
	public override void Load(string json, string file)
	{
		fileName = file;
		if(json != null)
		{
			Dictionary<string,string> data = (MiniJSON.Json.Deserialize(json) as Dictionary<string,object>).ToDSS();
			
			name = data["iterative"];
			description = data["description"];
			weight = float.Parse(data["weight"]);
			maxDex = int.Parse(data["maxDex"]);
			checkPenalty = int.Parse(data["checkPenalty"]);
			spellFailure = int.Parse(data["spellFailure"]);
			equipped = bool.Parse(data["equipped"]);
			buffs = new List<BuffDebuff>();
			List<object> objectsJson = MiniJSON.Json.Deserialize(data["buffs"]) as List<object>;
			foreach(string objJson in objectsJson)
			{
				BuffDebuff o = new BuffDebuff();
				o.Load(objJson, "");
				buffs.Add(o);
			}
			
			quantity = int.Parse(data["quantity"]);
			chargesRemaining = int.Parse(data["chargesRemaining"]);
			HasCharges = bool.Parse(data["HasCharges"]);
			worth = float.Parse(data["worth"]);
		}
	}
	
	public override string ToJSON()
	{
		Dictionary<string,string> data = new Dictionary<string, string>();

		data.Add("maxDex", maxDex.ToString());
		data.Add("checkPenalty", checkPenalty.ToString());
		data.Add("name", name.ToString());
		data.Add("description", description.ToString());
		data.Add("weight", weight.ToString());
		data.Add("spellFailure", spellFailure.ToString());
		data.Add("buffs", buffs.ToJSON());
		data.Add("slot",slot);
		data.Add("HasCharges", HasCharges.ToString());
		data.Add("chargesRemaining", chargesRemaining.ToString());
		data.Add("quantity", quantity.ToString());
		data.Add("worth", worth.ToString());
		data.Add("equipped", equipped.ToString());
		
		
		return MiniJSON.Json.Serialize(data);
	}
	
	public new ProtectiveItem DeepCopy()
	{
		ProtectiveItem a = new ProtectiveItem();
		a.Load(ToJSON(), fileName);
		return a;
	}
}
